layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 空闲车
     */
    var BasicPrivatecar = {
        tableId: "basicPrivatecarTable"
    };

    /**
     * 初始化表格的列
     */
    BasicPrivatecar.initColumn = function () {
        return [[
            {field: 'id', hide: true, title: '主键'},
            {field: 'privatecarState', title: '状态',templet: '#billstateTpl'},
            {field: 'operateName', title: '注册项目', style:'font-weight: 600;'},
            {field: 'privatecarFleetName', title: '承运商', style:'font-weight: 600;'},
            {field: 'privatecarCarnumber', title: '车牌号', style:'font-weight: 600;'},

            {field: 'driver1', title: '司机', style:'font-weight: 600;'},
            {field: 'tel1', title: '联系电话', style:'font-weight: 600;'},

            {field: 'privatecarSurevolume', title: '准载体积m3', style:'font-weight: 600;', sort: true},
            {field: 'privatecarColour', title: '车牌颜色', style:'font-weight: 600;'},
            {field: 'privatecarType', title: '车型', style:'font-weight: 600;'},
            {align: 'center', toolbar: '#tableBar', title: '操作' ,fixed: 'right'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    BasicPrivatecar.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        queryData['operateId'] = $("#operateId").val();
        queryData['privatecarFleetId'] = $("#privatecarFleetId").val();
        table.reload(BasicPrivatecar.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + BasicPrivatecar.tableId,
        url: Feng.ctxPath + '/orderTransportDispatch/privatecarlist',
        page: true,
        limit: 40,
        height: "full-60",
        cellMinWidth: 100,
        cols: BasicPrivatecar.initColumn()
    });


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        BasicPrivatecar.search();
    });
    
    //回填商品数据
    function confirm(data){
    	parent.MakeRailwayPlatformManageInfoDlg.data.carId = data.id;
    	parent.MakeRailwayPlatformManageInfoDlg.data.carNumber = data.privatecarCarnumber;
    	parent.MakeRailwayPlatformManageInfoDlg.data.carType = data.privatecarType;
    	parent.MakeRailwayPlatformManageInfoDlg.data.driver = data.driver1;
    	parent.MakeRailwayPlatformManageInfoDlg.data.tel = data.tel1;
    	var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    }
    
    // 双击行事件
    table.on('rowDouble(' + BasicPrivatecar.tableId + ')', function (obj) {
        var data = obj.data;
    	confirm(data);
    });


    // 工具条点击事件
    table.on('tool(' + BasicPrivatecar.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'xianze') {
    		confirm(data);
        } 
    });

});
